package com.song.shiro.result;

public class ResultEntity<T> {
    //结果体
    protected T data = null;
    //状态码
    protected Integer code = null;
    //信息
    protected String message = "";
    //
    protected Boolean success = true;

    private ResultEntity() {
        super();
    }

    private ResultEntity(Integer code) {
        this.code = code;
    }
    private ResultEntity(Integer code, Boolean success) {
        this.code = code;
        this.success = success;
    }

    public static ResultEntity create(Integer code, Boolean success) {
        return new ResultEntity(code,success);
    }

    public static ResultEntity success() {
        return create(200, true);
    }

    public static ResultEntity successCode(Integer code) {
        return create(code, true);
    }

    public static <T> ResultEntity success(Integer code, T data, String message) {
        return create(code, true).setData(data).setMessage(message);
    }

    public static <T> ResultEntity successCodeData(Integer code, T data) {
        return create(code, true).setData(data);
    }

    public static <T> ResultEntity successCodeMessage(Integer code, String message) {
        return create(code, true).setMessage(message);
    }

    public static <T> ResultEntity successDataMessage(T data, String message) {
        return success().setData(data).setMessage(message);
    }

    public static <T> ResultEntity successMessage(String message) {
        return success().setMessage(message);
    }

    public static <T> ResultEntity success(T data) {
        return success().setData(data);
    }

    public static ResultEntity fail() {
        return create(500, false);
    }

    public static ResultEntity failCode(Integer code) {
        return create(code, false);
    }

    public static <T> ResultEntity failDataMessage(T data, String message) {
        return fail().setData(data).setMessage(message);
    }

    public static <T> ResultEntity fail(T data) {
        return fail().setData(data);
    }

    public static <T> ResultEntity failMessage(String message) {
        return fail().setMessage(message);
    }

    public static <T> ResultEntity fail(Integer code, T data, String message) {
        return create(code, false).setData(data).setMessage(message);
    }

    public static <T> ResultEntity failCodeData(Integer code, T data) {
        return create(code, false).setData(data);
    }

    public static ResultEntity failCodeMessage(Integer code, String message) {
        return create(code, false).setMessage(message);
    }

    public boolean isSuccess() {
        return success != null && success;
    }

    public T getData() {
        return data;
    }

    public ResultEntity setData(T data) {
        this.data = data;
        return this;
    }

    public Integer getCode() {
        return code;
    }

    public ResultEntity setCode(Integer code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public ResultEntity setMessage(String message) {
        this.message = message;
        return this;
    }

    public ResultEntity(T data, Integer code, String message) {
        super();
        this.data = data;
        this.code = code;
        this.message = message;
    }

}
